#include "ustandard/ustandard_def.h"
#define um_run_times_start(N)\
if(1) {\
    struct timeval tv_sfksjlksf[2];\
    gettimeofday(&tv_sfksjlksf[0], NULL);\
    unsigned long times_sfksjlksf = (N);\
    while(times_sfksjlksf--) {




#define um_run_times_finish(SECOND)\
    }\
    gettimeofday(&tv_sfksjlksf[1], NULL);\
    double sec_sfksjlksf = (double)(tv_sfksjlksf[1].tv_sec - tv_sfksjlksf[0].tv_sec) + \
            (double)(tv_sfksjlksf[1].tv_usec - tv_sfksjlksf[0].tv_usec)/1e6;\
    SECOND = sec_sfksjlksf; \
}


#define PRINT_TCOST     \
    fprintf(fp, "----------cost time %lf .\n", sec);

int main()
{
    const char* items = "WIC";
    size_t nitems = strlen(items);
#define LEN 1024
    char str[LEN];
    char* s;
    size_t size;
    int i;
    size_t len;
    int times = 1000000;
    double sec = 0.0;
    FILE* fp = fopen("/tmp/ttt", "w");
    assert(NULL != fp);
    setbuf(fp, NULL);
    daemon(0, 0);

um_run_times_start(times)
    s = str;
    size = LEN;
    for(i=0; i<nitems; i++) {
        switch(items[i]) {
            case 'W':
            snprintf(s, size, "[%36s,%30s %6d]", "src/ustandard/ustandard.c", "ustandard_init_all_testcase", 123456);
            len = strlen(s);
            s += len;
            size -= len;
            break;

            case 'I':
            snprintf(s, size, "%5s:", "info");
            len = strlen(s);
            s += len;
            size -= len;
            break;

            case 'C':
            snprintf(s, size, "%s show %d + %d = %d \n", "this log", 1, 1, 1+1);
            len = strlen(s);
            s += len;
            size -= len;
            break;
        }
    }
    printf("%s", str);
um_run_times_finish(sec)
    PRINT_TCOST

    int kstd_is_daemon = 0;
um_run_times_start(times)
    if(kstd_is_daemon) {
        int a = 0;
        while(1) {a +=kstd_is_daemon; }
    }
um_run_times_finish(sec)
    PRINT_TCOST

um_run_times_start(times)
    s = str;
    size = 0;
    if(kstd_is_daemon) {
    snprintf(s, size, "[%36s,%30s %6d]", "src/ustandard/ustandard.c", "ustandard_init_all_testcase", 123456);
    }
um_run_times_finish(sec)
    PRINT_TCOST

um_run_times_start(times)
    printf("[%36s,%30s %6d]\n", "src/ustandard/ustandard.c", "ustandard_init_all_testcase", 123456);
um_run_times_finish(sec)
    PRINT_TCOST

    return 0;
}
